package com.example.payer

import android.view.View
import android.widget.ArrayAdapter
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.payer.adapter.PayerAdapter
import com.example.payer.databinding.ActivityPayerBinding
import com.example.payer.etity.Payer
import com.example.payer.vm.PayerViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/payer/PayerActivity")
class PayerActivity : BaseMvvmActivity<ActivityPayerBinding>() {
    private val payerViewModel:PayerViewModel by viewModels()
    var id:Int = 3
    override fun initView() {
        payerViewModel.getPayer(id)
        payerViewModel.mPayerSuccess.observe(this){
            mDataBinding.rv.run {
                layoutManager = LinearLayoutManager(this@PayerActivity)
                adapter = PayerAdapter(it).apply {
                    notifyDataSetChanged()
                    setOnItemClickListener(object :PayerAdapter.ItemOnClickListener{
                        override fun onClick(view: View, position: Int) {
                            ARouter.getInstance().build("/payer/PayerDetailActivity").withSerializable("payer",it[position]).navigation()
                        }
                    })
                }
            }
        }
        payerViewModel.mError.observe(this){
            ToastUtils.showLong("显示失败")
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_payer
}